#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
class Queue{
    private:
        struct node
        {
            int data;
            node *next;
        };
    public:
        node *front,*end;
        Queue();
        void push(int x);
        int pop();
        bool empty();
};
Queue::Queue()
{
    front= new node;
    front->next=NULL;
    end=front;
}
void Queue::push(int x)
{
    node *new_node =new node;
    new_node->data=x;
    new_node->next=NULL;
    end->next=new_node;
    end=new_node;
}
int Queue::pop()
{
    if(empty())
    {
        cout<<"Queue is empty"<<endl;
        return -1;
    }
    else {
        int x=front->next->data;
        node *temp=front->next;
        front->next=front->next->next;
        delete temp;
        return x;
    }
}
bool Queue::empty()
{
    if(front->next==NULL)
        return true;
    else
        return false;
}
int main()
{
    int n,x;
    Queue q;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        q.push(x);
    }
    //cout<<endl;
    while(!q.empty())
    {
        cout<<q.pop()<<" ";
    }
    cout<<endl;
    q.pop();
    return 0;
}